/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.managedbean;

import frm.billingAndPaymentProcessing.entity.InvoiceEntity;
import frm.billingAndPaymentProcessing.session.InvoiceSessionBean;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.ToggleEvent;

/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class ViewAllInvoicesManagedBean {
private InvoiceEntity invoice;
private String status;

@EJB
InvoiceSessionBean invoiceSessionBean;
    /** Creates a new instance of ViewAllInvoicesManagedBean */
    public ViewAllInvoicesManagedBean() {
        invoice = new InvoiceEntity();
    }
    
    public List<InvoiceEntity> getAllInvoices(){
      List<InvoiceEntity> invoiceList  = invoiceSessionBean.getAllInvoice();
      return invoiceList;
    }
    public List<InvoiceEntity> getAolished(){
        List<InvoiceEntity> ainvoiceList = invoiceSessionBean.getAbolishedInvoice();
        return ainvoiceList;
    }
    public void viewInvoice(InvoiceEntity invoiceEntity) throws IOException{
       invoice = invoiceEntity;
       FacesContext.getCurrentInstance().getExternalContext().getFlash().put("invoice", invoice);
       FacesContext.getCurrentInstance().getExternalContext().redirect("displayInvoice.xhtml");  
    }
    
    public void updateInvoice(InvoiceEntity invoiceEntity) throws IOException{
        invoice = invoiceEntity;
       FacesContext.getCurrentInstance().getExternalContext().getFlash().put("invoice", invoice);
       FacesContext.getCurrentInstance().getExternalContext().redirect("updateInvoice.xhtml");  
    }
//    public void removeInvoice(InvoiceEntity invoiceEntity) throws IOException{
//        //invoice = invoiceEntity;
//        //dcheck the employee right
//        //pop out a window to ask for confirmation
//        invoiceSessionBean.removeInvoice(invoiceEntity);  
//    } 
        public void handleToggle(ToggleEvent event) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Fieldset Toggled", "Visibility:" + event.getVisibility());

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    public InvoiceEntity getInvoice() {
        return invoice;
    }

    public void setInvoice(InvoiceEntity invoice) {
        this.invoice = invoice;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
